var update = true;
var startmenu;
var show = true;

Ext.define('WebMeV.controller.StartMenu', {
    extend: 'Ext.app.Controller',

    views : ['StartMenu'],

    init: function() {
        this.control({
            'ribbonbar': {
                afterrender: function(cmp){
                    Ext.get('ribbonbar').on('click', function(evt, el, o){ 
                        //or you can write your code inline here
                        if(evt.getX() < 60)
                            if(evt.getX() > 3)
                                if(evt.getY() < 24)
                                    if(evt.getY() > 2){
                                        if(show){
                                            if(!startmenu){
                                                startmenu = Ext.create('WebMeV.view.StartMenu');
                                                startmenu.setPosition(0, 23, false);                                                
                                                startmenu.show();
                                                if(!Ext.isIE){
                                                    startmenu.getEl().setStyle('opacity','0');
                                                    startmenu.getEl().fadeIn({
                                                        endOpacity: 1, 
                                                        duration: 500
                                                    });
                                                }                                               
                                                show = false;
                                            } else {
                                                startmenu.show();
                                                if(!Ext.isIE)
                                                    startmenu.getEl().fadeIn({
                                                        endOpacity: 1, 
                                                        duration: 500
                                                    });
                                                show = false;
                                            }
                                        } else {
                                            show = true;
                                            if(ex)
                                                ex.hide();
                                            if(!Ext.isIE){
                                                startmenu.getEl().fadeOut({
                                                    endOpacity: 0, 
                                                    duration: 1000
                                                });
                                                Ext.Function.defer(startmenu.hide, 1000, startmenu);                                                   
                                            } else {
                                                startmenu.hide();
                                            }
                                        }
                                    }
                    });
                    Ext.get('ribbonbar').on('mouseover', function(evt, el, o){ 
                        if(evt.getX() < 60)
                            if(evt.getX() > 3)
                                if(evt.getY() < 24)
                                    if(evt.getY() > 2){
                                        Ext.fly('ribbonbar').addCls('ui-ribbonbar2');
                                        update = true;
                                    }
                    });
                    Ext.get('ribbonbar').on('mouseout', function(evt, el, o){ 
                        if(update){
                            if(evt.getX() > 60){
                                Ext.fly('ribbonbar').removeCls('ui-ribbonbar2');
                                update = false;
                            } else {
                                if(evt.getY() > 24){
                                    Ext.fly('ribbonbar').removeCls('ui-ribbonbar2');
                                    update = false;
                                }
                            }
                            if(evt.getX() < 3){
                                Ext.fly('ribbonbar').removeCls('ui-ribbonbar2');
                                update = false;
                            } 
                        }
                    });
                }
            }   
        });
    }  
});


